﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;

namespace Raytracererer
{
    public partial class Form1 : Form
    {
        Scene scene = new Scene();
        Camera cam = new Camera(new Vector3(-4, 0, 0), new Vector3(1, 0, 0));
        public Form1()
        {
            scene.cam = cam;
            InitializeComponent();
            Random r = new Random();

            //for (int i = 0; i < 4; i++)
            //{
            //    scene.primitives.Add(
            //        new Sphere(r.NextDouble() * .3,
            //            new Vector3(2, -0.5, -0.5) + new Vector3(r.NextDouble(), 3 - r.NextDouble() * 5, (r.NextDouble() - 0.5) * 10),
            //                new Color(r.NextDouble(), r.NextDouble(), r.NextDouble())) { transparency = .99, refractionIndex = 1.3 });
            //}
            for (int i = 0; i < 10; i++)
            {
                double a1 = r.NextDouble() * 2 * Math.PI;
                double a2 = r.NextDouble() * 2 * Math.PI;
                double d = r.NextDouble() * .6;
                scene.primitives.Add(new Sphere(r.NextDouble()*0.05, new Vector3(1, 0, 0)+new Vector3(d*Math.Sin(a1)*Math.Cos(a2),d*Math.Sin(a1)*Math.Sin(a2),d*Math.Cos(a1)), new Color(0)) { transparency = .99, refractionIndex = 1 });
            }
            scene.primitives.Add(new Sphere(.7, new Vector3(1, 0, 0), new Color(0)) { transparency = .99, refractionIndex = 1 });
            scene.primitives.Add(new Sphere(.2, new Vector3(1, 0, 0), new Color(0)) { transparency = .99, refractionIndex = 1.0 });

            //scene.primitives.Add(new Cylinder(new Vector3(3, 0, 0), new Vector3(-1, 1, 0), 0.3, new Color(0.2, 0.7, 0.3), 1));
            scene.primitives.Add(new TexturedPlane(new Vector3(5, 0.5, 0), new Vector3(-0.00000000001, -1, 0), new Color(1), new Bitmap(@"chess1.jpg")) { reflectivity = 0, scale = 1 });
            scene.primitives.Add(new TexturedPlane(new Vector3(5, 2,2), new Vector3(-1, 0, 0), new Color(1), new Bitmap(@"chess1.jpg")) { scale = .3 });
            //scene.primitives.Add(new TexturedPlane(new Vector3(-4, 0, 0), new Vector3(1, 0, 0), new Color(.3), new Bitmap(@"chess1.jpg")) { reflectivity = 0 });

            //                scene.primitives.Add(new TexturedSphere(.1, new Vector3(2, 0, 0), new Color(1, 1, 1), new Bitmap(@"chess1.jpg")));
            //            scene.primitives.Add(new Sphere(.7, new Vector3(2, 0, 1), new Color(0, 1, 1)));
            //            scene.primitives.Add(new Sphere(.2, new Vector3(2, 0, -1), new Color(1, 1, 1)));
            //scene.primitives.Add(new TexturedSphere(.005, new Vector3(1, 0, 0), new Color(0, 0, 0), new Bitmap("C:\\Users\\Markus\\Pictures\\cyberpunk.jpg")));

            //scene.lights.Add(new Light(new Vector3(-2, -1, -2), 2 * new Color(.3, 0.3, 0.3)));
            //scene.lights.Add(new Light(new Vector3(-1, 4, -2), new Color(.4)));
            scene.lights.Add(new Light(new Vector3(0, -3, 0), new Color(2.8, 2.8, 3)));
            //scene.lights.Add(new Light(new Vector3(3, -1, 2), 0.5*new Color(0, 0, 4)));
            scene.lights.Add(new Light(new Vector3(3, -1, -2), new Color(2, 0, 0)));
            //scene.primitives.Add(new Sphere(0.3, new Vector3(3, 0, 0), new Color(5)));
            //scene.lights.Add(new Light(new Vector3(3.8, 0, 1), new Color(.5, .5, 10)));
            //pictureBox1.Image = new Renderer().Render(scene, cam, new RenderInfo(pictureBox1.Width, pictureBox1.Height, 1));
            
            
            //all kod ovanför detta ignoreras med följande rad
            //scene = new GlassSphereScene();
            scene = new LensScene();
            
            button2_Click(null, null);
        }


        private void button1_Click(object sender, EventArgs e)
        {
            Stopwatch t = new Stopwatch();
            t.Start();
            pictureBox1.Image = new Renderer().Render(scene, new RenderInfo(pictureBox1.Width, pictureBox1.Height, 1));
            label1.Text = t.ElapsedMilliseconds + " ms";
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Stopwatch t = new Stopwatch();
            t.Start();
            pictureBox1.Image = new Renderer().ParalellRender(scene, new RenderInfo(pictureBox1.Width, pictureBox1.Height, 1));
            label1.Text = t.ToString();
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }
    }
}
